package com.ms.mall.order.controller;

import com.ms.mall.order.config.TeacherProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.server.WebServer;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class EchoController {
    @Value("${spring.application.name}")
    private String applicationName;
    @Value("${server.port}")
    private String port;

    @Autowired
    private ServletWebServerApplicationContext context;
    @Autowired
    TeacherProperties teacherProperties;
    @GetMapping(value = "/echo/{string}")
    public String echo(@PathVariable String string) {
        log.info("application:{},port:{}",applicationName,port);
        WebServer webServer = context.getWebServer();
        log.info("context.application:{},context.port:{}",context.getApplicationName(),webServer.getPort());
        log.info("name:{},age:{}",teacherProperties.getName(),teacherProperties.getAge());
        return "Hello Nacos Discovery " + string;
    }
}